<template>
  <div class="app-container table-container">
    <el-row>
      <el-col :span="20">
        <el-form ref="queryForm" :model="searchDate" :inline="true" label-width="68px">
          <el-form-item label="活动名称">
            <el-input
              v-model="searchDate.activityName"
              filterable
              placeholder="请输入活动名称"
              size="small"
              @change="changeAuditState"
            />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @cliclk="queryActivity">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="restart">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="4">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="medium"
          @click="addTictDialog"
        >新增活动
        </el-button>
      </el-col>
    </el-row>

    <el-table
      :data="tictData"
      size="mini"
      :header-cell-style="{background:'#e5ecf1',fontWeight: 'bold',textAlign: 'center'}"
      highlight-current-row
      border
      style="font-size: 16px;"
      @current-change="userChge"
    >
      <el-table-column prop="activityName" label="活动名称" min-width="80" />
      <el-table-column prop="activityCode" label="活动编码" min-width="50" />

      <el-table-column prop="startTime" label="活动开始时间" min-width="50" >
        <template slot-scope="scope">
        {{parseTime(scope.row.startTime)}}
      </template>
      </el-table-column>
      <el-table-column prop="endTime" label="活动结束时间" min-width="50">
      <template slot-scope="scope">
        {{parseTime(scope.row.endTime)}}
      </template>
      </el-table-column>
      <el-table-column prop="activityType" label="活动状态" min-width="50" />
      <el-table-column prop="activityCreator" label="创建人" min-width="50" />
      <el-table-column width="180" fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            @click="editActivity( scope.row )"
          >关联
          </el-button>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="deleteTict( scope.row )"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="left" class="pagination">
      <el-pagination
        background
        :current-page="tictPage.currentPage"
        :page-sizes="[10, 20, 30]"
        :page-size="tictPage.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tictPage.totalElements"
        @size-change="userSize"
        @current-change="pgChge"
      />
    </el-row>
  </div>
</template>

<script>
import { getDataForSP, writePageInfo } from '../../../utils/webUtils.js'
import editActivity from './editActivity.vue'
import addActivity from './addActivity.vue'

export default {
  name: 'TictReport',
  components: { addActivity, editActivity },
  data() {
    return {
      currentEdituuid: '',
      addDialogVisible: false,
      editDialogVisible: false,
      formAlignLeft: 'left',
      pwdShow: false,
      userSchOn: '',
      userEdit: false,
      uuid: '',
      searchDate: { activityName: '' },
      tictData: [],
      tictPage: {
        pageSize: 10, // 每页显示条目个数
        currentPage: 1, // 当前页数
        totalElements: 0,
        searchData: {
          merchUuid: '',
          activityName: ''
        }
      },
      merchants: { name: '', uuid: '' }
    }
  },
  created() {
    this.queryActivity(this.searchDate)
  },
  methods: {
    restart() {
      this.searchDate.activityName = ''
      this.queryActivity(this.searchDate)
    },
    /**
       * 打开新增对话框
       */
    addTictDialog() {
      this.$router.push("/addTicActivity")
    },
    editActivity(val) {
      this.uuid = val.id
      this.$router.push("/editTicActivity/"+this.uuid)
    },
    // 查询方法
    changeAuditState() {
      this.queryActivity(this.searchDate)
    },
    editSalesPlan(msg) {
      this.drawer = msg
    },
    deleteTict(val) {
      this.$confirm('确认删除 ' + val.activityName + ' ?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.request({
          method: 'delete',
          url: './tck/activity/del/' + val.id,
          data: {}
        }).then(() => {
          this.$message({
            message: '删除成功!',
            type: 'success'
          })
          this.queryActivity(this.searchDate)
        }).catch(error => {
          console.log(error)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    userChge(val) {
      if (this.userEdit) {
        this.uuid = val.uuid
      }
    },
    // 获取所有数据
    queryActivity(param) {
      this.tictPage.searchData.activityName = param.activityName
            this.axios.request({
              method: 'get',
              url: './tck/activity/findAllActivity',
              params: getDataForSP(this.tictPage)
            }).then(response => {
              this.tictData = response.data.data
              writePageInfo(this.tictPage, response.data)
            }).catch(error => {
              console.log(error)
            })


    },
    // 列表分页
    userSize: function(pageSize) {
      this.tictPage.pageSize = pageSize
      if (this.tictPage.currentPage === 1) {
        if (this.userSchOn !== '') {
          // this.userSearch();
        } else {
          this.queryActivity(this.searchDate)
        }
      }
      this.tictPage.currentPage = 1
    },
    pgChge(currentPage) {
      this.tictPage.currentPage = currentPage
      this.queryActivity(this.searchDate)
    }
  }
}
</script>

<style scoped lang="scss">
  @import "@/styles/table.scss";
  .app-container{
  .pagination{
    padding: 10px 0;
  }
  }

</style>
